<?php

namespace app\admin\model\pay\code;

use think\Model;


class Lists extends Model
{

    

    

    // 表名
    protected $name = 'pay_code_lists';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'paytype_text',
        'codetype_text'
    ];
    

    
    public function getStatusList()
    {
        return ['正常' => __('正常'), '禁用' => __('禁用')];
    }

    public function getPaytypeList()
    {
        return ['wechat' => __('Wechat'), 'alipay' => __('Alipay'), 'unionpay' => __('Unionpay')];
    }

    public function getCodetypeList()
    {
        return ['0' => __('通用'), '1' => __('定向')];
    }

    public function getIsareaList()
    {
        return ['0' => __('否'), '1' => __('是')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPaytypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['paytype'] ?? '');
        $valueArr = explode(',', $value);
        $list = $this->getPaytypeList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function getCodetypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['codetype']) ? $data['codetype'] : '');
        $list = $this->getCodetypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setPaytypeAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }


    public function platform()
    {
        return $this->belongsTo('app\admin\model\pay\Platform', 'pay_platform_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
